import { HttpErrorPage, LoginRoute, RedirectRoute, ReloadRoute } from './base'
import { PageEnum } from '@/enums/pageEnum'
import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import { Layout } from './constant'
import modules from './modules'
import type { App } from 'vue'
import { createRouterGuards } from './route-guards'

const RootRoute: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Root',
    redirect: PageEnum.BASE_HOME,
    component: Layout,
    meta: {
      title: 'Root'
    },
    children: [
      ...HttpErrorPage,
      ...RedirectRoute,
      modules.projectRoutes,
      modules.chartRoutes,
      modules.previewRoutes,
      modules.editRoutes
    ]
  }
]

export const constantRouter: any[] = [LoginRoute, ...RootRoute, ReloadRoute]

const router = createRouter({
  history: createWebHashHistory(''),
  routes: constantRouter,
  strict: true
})

export function setupRouter(app: App) {
  app.use(router)
  // 创建路由守卫
  createRouterGuards(router)
}

export default router
